#include<stack>
#include<iostream>
using namespace std;

void CheckMatch(char const* str)
{
    char const* p = str;
    stack<char> bracketStack;
    
    for (; '\0' != *p; ++p)
    {
        if (('(' == *p) || ('[' == *p) || ('{' == *p))
        {
            bracketStack.push(*p);
        }
        else if ((')' == *p) || (']' == *p) || ('}' == *p))
        {
            if (bracketStack.empty())
            {
                cout<< "Not Matched!\n";
                return;
            }
            else
            {
                char bracket = bracketStack.top();
                if( ('(' == bracket && ')' == *p)
                || ('[' == bracket && ']' == *p)
                || ('{' == bracket && '}' == *p))
                {
                    bracketStack.pop();
                }
				else
				{
					cout<< "Not Matched!\n";
					return;
				}
            }
        }
        else
        {
            cout<< "Not Matched!\n";
            return;
        }
    }
    
    if (bracketStack.empty())
    {
        cout<< "Matched!\n";
    }
	else
	{
		cout<< "Not Matched!\n";
	}
}

int main(void)
{
    CheckMatch("([]())");
    CheckMatch("[([][])]");
    CheckMatch("[(])");
    CheckMatch("([()]");
    CheckMatch("(()])");
    
    system("pause");
}
